<?php defined('IN_IA') or exit('Access Denied'); ?>
<?php include page("header-base"); ?>

<?php if ($operation == 'display') { ?>
    <div class="panel ">
        <h3 class="custom_page_header"> 分销商分成发放</h3>
        <div class="panel-body">
            <form action="" method="get" class="form-horizontal" onsubmit="return check_sub();" role="form" id="form1">
                <input type="hidden" name="sub" value="ff"/>
                <input type="hidden" name="mod" value="site" />
                <input type="hidden" name="m" value="eshop"/>
                <input type="hidden" name="do" value="commission"/>
                <input type="hidden" name="act" value="divided"/>
                <input type="hidden" name="op" value="display"/>
                <input type="hidden" name="beid" value="<?php echo $GLOBALS['_CMS']['beid']; ?>"/>

                <div class="form-group">
                    <label class="col-sm-2 col-md-2 col-lg-1 control-label">发放金额</label>
                    <div class="col-sm-3">
                        <input type="text" class="form-control" id="price" name="price" onkeyup="value=value.replace(/[^\d\.]/g,'')" onblur="value=value.replace(/[^\d\.]/g,'')" placeholder='请输入发放金额'/>
                    </div>
                    <label class="col-sm-2 col-md-2 col-lg-1 control-label">分销商等级</label>
                    <div class="col-sm-3">
                        <select name='agentlevel' id="agentlevel" class='form-control'>
                            <option value=''>==选择分销商==</option>
                            <?php if (is_array($agentlevels)) {
                                foreach ($agentlevels as $level) { ?>
                                    <option value='<?php echo $level['id']; ?>'
                                            <?php if ($_GPC['agentlevel'] == $level['id']) { ?>selected<?php } ?>><?php echo $level['levelname']; ?></option>
                                <?php }
                            } ?>
                        </select>
                    </div>
                    <div class="col-sm-3">
                        <button class="btn btn-default"><i class="fa fa-money"></i> 发放</button>
                        <input type="hidden" name="token" value="<?php echo $_W['token']; ?>"/>
                    </div>
                </div>

            </form>
        </div>

        <div class="panel-body">
            <table class="table table-hover table-responsive">
                <thead class="navbar-inner">
                <tr>
                    <th width="10%">ID</th>
                    <th width="15%">发放金额</th>
                    <th width="20%">分销商等级</th>
                    <th width="15%">分销商人数</th>
                    <th width="15%">发放时间</th>
                    <th width="15%">操作人</th>
                    <th width="15%">状态</th>
                </tr>
                </thead>
                <tbody>
                <?php if (is_array($list)) {
                    foreach ($list as $row) { ?>
                        <tr>
							<td><?php echo $row['id']; ?></td>
                            <td><?php echo $row['price']; ?></td>
                            <td><?php echo $row['agentgrade']; ?></td>
                            <td><?php echo $row['agentnum']; ?></td>
                            <td><?php echo date('Y-m-d H:i:s',$row['add_time']); ?></td>
                            <td><?php echo $row['name']; ?></td>
                            <td>已完成</td>
                        </tr>
                    <?php }
                } ?>
                </tbody>
            </table>
            <?php echo $pager; ?>
        </div>
    </div>
<?php } else if ($operation == 'detail') { ?>

    <form action="" method='post' class='form-horizontal'>
        <input type="hidden" name="id" value="<?php echo $member['id']; ?>">
        <input type="hidden" name="mod" value="site"/>
        <input type="hidden" name="m" value="eshop"/>
        <input type="hidden" name="do" value="commission"/>
        <input type="hidden" name="act" value="agent"/>
        <input type="hidden" name="op" value="detail"/>
        <div class='panel panel-default'>
            <h3 class="custom_page_header"> 分销商详细信息</h3>
            <div class='panel-body'>

                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">粉丝</label>
                    <div class="col-sm-9 col-xs-12">
                        <img onerror="this.src='<?php echo RESOURCE_ROOT; ?>eshop/mobile/default/static/images/tx.png'"
                             src='<?php echo $member['avatar']; ?>'
                             style='width:100px;height:100px;padding:1px;border:1px solid #ccc'/>
                        <?php echo $member['nickname']; ?>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">OPENID</label>
                    <div class="col-sm-9 col-xs-12">
                        <div class="form-control-static"><?php echo $member['openid']; ?></div>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">真实姓名</label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="text" name="data[realname]" class="form-control"
                               value="<?php echo $member['realname']; ?>"/>

                    </div>
                </div>

                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">手机号码</label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="text" name="data[mobile]" class="form-control"
                               value="<?php echo $member['mobile']; ?>"/>

                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">微信号</label>
                    <div class="col-sm-9 col-xs-12">
                        <input type="text" name="data[weixin]" class="form-control"
                               value="<?php echo $member['weixin']; ?>"/>

                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">分销商等级</label>
                    <div class="col-sm-9 col-xs-12">

                        <select name='data[agentlevel]' class='form-control'>
                            <option value='0'>普通等级</option>
                            <?php if (is_array($agentlevels)) {
                                foreach ($agentlevels as $level) { ?>
                                    <option value='<?php echo $level['id']; ?>'
                                            <?php if ($member['agentlevel'] == $level['id']) { ?>selected<?php } ?>><?php echo $level['levelname']; ?></option>
                                <?php }
                            } ?>
                        </select>

                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">累计佣金</label>
                    <div class="col-sm-9 col-xs-12">
                        <div class='form-control-static'> <?php echo $member['commission_total']; ?></div>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">已打款佣金</label>
                    <div class="col-sm-9 col-xs-12">
                        <div class='form-control-static'> <?php echo $member['commission_pay']; ?></div>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">注册时间</label>
                    <div class="col-sm-9 col-xs-12">
                        <div class='form-control-static'><?php echo date('Y-m-d H:i:s', $member['createtime']); ?></div>
                    </div>
                </div>
                <?php if ($member['agenttime'] != '1970-01-01 08:00') { ?>
                    <div class="form-group">
                        <label class="col-xs-12 col-sm-3 col-md-2 control-label">成为代理时间</label>
                        <div class="col-sm-9 col-xs-12">
                            <div class='form-control-static'><?php if (!strexists('1970', $member['agenttime'])) { ?><?php echo $member['agenttime']; ?><?php } else { ?>----------<?php } ?></div>
                        </div>
                    </div>
                <?php } ?>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">分销商权限</label>
                    <div class="col-sm-9 col-xs-12">

                        <label class="radio-inline"><input type="radio" name="data[isagent]" value="1"
                                                           <?php if ($member['isagent'] == 1) { ?>checked<?php } ?>>是</label>
                        <label class="radio-inline"><input type="radio" name="data[isagent]" value="0"
                                                           <?php if ($member['isagent'] == 0) { ?>checked<?php } ?>>否</label>


                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">固定上级</label>
                    <div class="col-sm-9 col-xs-12">

                        <label class="radio-inline"><input type="radio" name="data[fixagentid]" value="1"
                                                           <?php if ($member['fixagentid'] == 1) { ?>checked<?php } ?>>是</label>
                        <label class="radio-inline"><input type="radio" name="data[fixagentid]" value="0"
                                                           <?php if ($member['fixagentid'] == 0) { ?>checked<?php } ?>>否</label>


                    </div>
                </div>
                <?php $dingtalk_setting = globalSetting('dingtalk'); ?>
                <?php if (!empty($dingtalk_setting['fastlogin_open'])) { ?>
                    <div class="form-group">
                        <label class="col-xs-12 col-sm-3 col-md-2 control-label">阿里钉钉</label>
                        <div class="col-sm-9 col-xs-12">
                            <div class="form-control-static">
                                <?php if (!empty($member['base_member']) && !empty($member['base_member']['dingtalk_openid'])) { ?>
                                    <label class="label label-primary">绑定</label>阿里钉钉&nbsp;openid：<?php echo $member['base_member']['dingtalk_openid']; ?>
                                <?php } else { ?> <label class="label label-default">未绑定</label>  <?php } ?>
                            </div>
                        </div>
                    </div>
                <?php } ?>
                <?php if (false) { ?>
                    <div class="form-group">
                        <label class="col-xs-12 col-sm-3 col-md-2 control-label">审核通过</label>
                        <div class="col-sm-9 col-xs-12">

                            <label class="radio-inline"><input type="radio" name="data[status]" value="1"
                                                               <?php if ($member['status'] == 1) { ?>checked<?php } ?>>是</label>
                            <label class="radio-inline"><input type="radio" name="data[status]" value="0"
                                                               <?php if ($member['status'] == 0) { ?>checked<?php } ?>>否</label>
                            <input type='hidden' name='oldstatus' value="<?php echo $member['status']; ?>"/>

                        </div>
                    </div>
                <?php } ?>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">强制不自动升级</label>
                    <div class="col-sm-9 col-xs-12">

                        <label class="radio-inline"><input type="radio" name="data[agentnotupgrade]" value="0"
                                                           <?php if ($member['agentnotupgrade'] == 0) { ?>checked<?php } ?>>允许自动升级</label>
                        <label class="radio-inline"><input type="radio" name="data[agentnotupgrade]" value="1"
                                                           <?php if ($member['agentnotupgrade'] == 1) { ?>checked<?php } ?>>强制不自动升级</label>
                        <span class="help-block">如果强制不自动升级，满足任何条件，此分销商的级别也不会改变</span>

                    </div>
                </div>


                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">黑名单</label>
                    <div class="col-sm-9 col-xs-12">
                        <input type='hidden' name='oldagentblack' value="<?php echo $member['agentblack']; ?>"/>

                        <label class="radio-inline"><input type="radio" name="data[agentblack]" value="1"
                                                           <?php if ($member['agentblack'] == 1) { ?>checked<?php } ?>>是</label>
                        <label class="radio-inline"><input type="radio" name="data[agentblack]" value="0"
                                                           <?php if ($member['agentblack'] == 0) { ?>checked<?php } ?>>否</label>

                    </div>
                </div>

                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">备注</label>
                    <div class="col-sm-9 col-xs-12">

                        <textarea name="content" class='form-control'><?php echo $member['content']; ?></textarea>

                    </div>
                </div>

            </div>


            <div class='panel-body'>

                <div class="form-group"></div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
                    <div class="col-sm-9 col-xs-12">

                        <input type="submit" name="submit" value="提交" class="btn btn-primary col-lg-1"/>
                        <input type="hidden" name="token" value="<?php echo $_W['token']; ?>"/>

                        <input type="button" name="back" onclick='history.back()' style='margin-left:10px;' value="返回列表"
                               class="btn btn-default"/>
                    </div>
                </div>


            </div>


        </div>

    </form>

<?php } ?>
<script>
function check_sub(){
	if (confirm('确认要发放奖金吗?')){
		var price = $('#price').val();
		if(!price){
			util.message('请输入金额');
			return false;
		}
		var agentlevel = $('#agentlevel').val();
		if(!agentlevel){
			util.message('请选择分销商');
			return false;
		}
		return true;
	}
	return false;
}
</script>
<?php include page("footer-base"); ?>